package com.tanhua.server.controller;


import com.tanhua.server.service.VideoService;
import com.tanhua.server.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("management/manage")
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 查询视频记录
     * @param page
     * @param pagesize
     * @param uid
     * @return
     */
    @GetMapping("videos")
    public ResponseEntity<PageResult> queryVideos(@RequestParam(value = "page",defaultValue = "1")Integer page,
                                                  @RequestParam(value = "pagesize",defaultValue = "10")Integer pagesize,
                                                  @RequestParam(value = "uid",required = true) Integer uid,
                                                  @RequestParam(value = "sortProp",required = true)String sortProp,
                                                  @RequestParam(value = "sortOrder",required = true)String sortOrder){

        try {
            PageResult pageResult = videoService.queryVideos(page,pagesize,uid,sortProp,sortOrder);
            if (pageResult.getItems() != null){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
